import request from '../utils/request';
import Qs from 'qs';

const path = "/api";

// 变成form-data传参
const getFormdata = (obj) => {
    return Qs.stringify(obj);
}

// 用户登录
export const userLogin = (params) => {
    return request(`${path}/kpi/login`, {
        method: 'POST',
        data: getFormdata(params)
    })
}

// 获取当前登录用户信息
export const getUserInfo = () => {
    return request(`${path}/kpi/deptUser/userinfo`)
}

// 退出登录
export const userLogout = () => {
    return request(`${path}/kpi/logoutUser`)
}

// 根据部门id获取部门用户列表
export const getUserListByDeptId = (id) => {
    return request(`${path}/kpi/dept/getUserListByDeptId?deptid=${id || 1}`)
}

// 根据用户获取部门列表
export const getALLDept = () => {
    return request(`${path}/kpi/dept/getDeptByUser`)
}

// 获取所有部门
export const getAllDepts = () => {
    return request(`${path}/kpi/dept/getALLDept`)
}

// 打分
export const addScord = (params) => {
    return request(`${path}/kpi/scoringRecord/addList`, {
        method: 'POST',
        data: params
    })
}

// 获取个人分数
export const getUserScore = () => {
    return request(`${path}/kpi/scoringRecord/getScoreByuser`)
}

// 下载报表
export const getReport = (id) => {
    return request(`${path}/kpi/scoringRecord/downloadFile?deptid=${id}`)
}

// 下载报表地址
export const reportUrl = `${path}/kpi/scoringRecord/downloadFile?deptid=`;

// 修改密码
export const changePwd = (params) => {
    return request(`${path}/kpi/consumer/pwd`, {
        method: 'PUT',
        data: params
    })
}

// 查询部门打分记录
export const getDeptRecord = (params) => {
    return request(`${path}/kpi/scoringRecord/getList/dept?page=${params.page || 1}&pageSize=${params.pageSize || 10}`)
}

// 查询个人打分记录
export const getUserRecord = (params) => {
    return request(`${path}/kpi/scoringRecord/getList/user?page=${params.page || 1}&pageSize=${params.pageSize || 10}`)
}

// 分页获取部门信息
export const getDeptInfo = (params) => {
    return request(`${path}/kpi/dept/getList?page=${params.page || 1}&pageSize=${params.pageSize || 10}`)
}

// 新增部门
export const addDept = (params) => {
    return request(`${path}/kpi/dept/add`, {
        method: "POST",
        data: params
    })
}

// 修改部门
export const updateDept = (params) => {
    return request(`${path}/kpi/dept/updateById`, {
        method: "PUT",
        data: params
    })
}

// 删除部门
export const deleteDept = (id) => {
    return request(`${path}/kpi/dept/deleteById?id=${id}`, {
        method: 'DELETE'
    })
}

// 获取职务列表
export const getRoles = (params) => {
    return request(`${path}/kpi/role/getList?page=${params.page || 1}&pageSize=${params.pageSize || 10}`)
}

// 新增职务
export const addRole = (params) => {
    return request(`${path}/kpi/role/add`, {
        method: "POST",
        data: params
    })
}

// 修改职务
export const updateRole = (params) => {
    return request(`${path}/kpi/role/update`, {
        method: "PUT",
        data: params
    })
}

// 删除职务
export const deleteRole = (id) => {
    return request(`${path}/kpi/role/delete`, {
        data: { id },
        method: 'DELETE'
    })
}

// 分页获取打分规则列表
export const getKpiRules = (params) => {
    return request(`${path}/kpi/kpiRules/getList?search=${params.searchName}&page=${params.page || 1}&pageSize=${params.pageSize || 10}`)
}

// 新增打分规则
export const addKpiRules = (params) => {
    return request(`${path}/kpi/kpiRules/addList`, {
        method: "POST",
        data: params
    })
}

// 修改打分规则
export const updateKpiRule = (params) => {
    return request(`${path}/kpi/kpiRules/updateById`, {
        method: "PUT",
        data: params
    })
}

// 删除打分规则
export const deleteKpiRule = (id) => {
    return request(`${path}/kpi/kpiRules/deleteById?id=${id}`, {
        method: 'DELETE'
    })
}

// 新增用户
export const addUser = (params) => {
    return request(`${path}/kpi/user/one`, {
        method: "POST",
        data: params
    })
}

// 删除用户
export const deleteUser = (id) => {
    return request(`${path}/kpi/user/deleteById?uid=${id}`, {
        method: 'DELETE'
    })
}

// 获取查询用户列表
export const getUsers = (params) => {
    return request(`${path}/kpi/user/getList?search=${params.searchName}&page=${params.page||1}&pageSize=${params.pageSize||10}`)
}

// 修改员工
export const updateUser = (params) => {
    return request(`${path}/kpi/user/updateById`, {
        method: "PUT",
        data: params
    })
}

// 获取打分系数列表
export const getScoredType = (params) => {
    return request(`${path}/kpi/scoredType/getList?page=${params.page || 1}&pageSize=${params.pageSize || 10}`)
}

// 新增打分系数
export const addScoredType = (params) => {
    return request(`${path}/kpi/scoredType/add`, {
        method: "POST",
        data: params
    })
}

// 更新打分系数
export const updateScoredType = (params) => {
    return request(`${path}/kpi/scoredType/updateById`, {
        method: "PUT",
        data: params
    })
}

// 删除打分系数
export const deleteScoredType = (id) => {
    return request(`${path}/kpi/scoredType/deleteById?id=${id}`, {
        method: 'DELETE'
    })
}

// 根据部门或用户id获取评分列表
export const getScoredTypeById = (id) => {
    return request(`${path}/kpi/scoredType/getScoredByUserId?userid=${id}`)
}